﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using NewsAggregatorLibrary;

namespace NewsAggregator
{
    public partial class SearchView : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string key = Request.QueryString["key"];
            if (key != null)
            {
                SearchByKeyword(key);
            }
        }

        public void SearchByKeyword(string keyword) {
            StoriesMemberCollection stories = StoriesMember.RetrieveByKeywordSearch(keyword);

            //ScriptManager.RegisterStartupScript(Page, Page.GetType(), "SomestartupScript", " alert(' page loaded ');", true);
            hiddensearchvalue.Value = keyword;
            StoriesMemberCollection returnStories = new StoriesMemberCollection();
            int numberOfObjectsPerPage = 10;
            returnStories.AddRange(stories
              .Skip(numberOfObjectsPerPage * 0)
              .Take(numberOfObjectsPerPage));
            srchStroriesRepeater.DataSource = returnStories;
            srchStroriesRepeater.DataBind();
        }
    }
}